package com.fengxu.gamescript.data;

import java.io.File;
import java.io.Serializable;

/**
 * 脚本属性
 */
public class ScriptProp implements Serializable {

    private static final long serialVersionUID = 001L;

    // 脚本id
    private String id;

    // 脚本路径
    private String path;

    // 脚本类型
    private String type;

    // 脚本文件名
    private String name;

    // 脚本大小
    private Long size;

    // 脚本更新时间
    private Long updateTime;

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getSize() {
        return size;
    }

    public void setSize(Long size) {
        this.size = size;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    /**
     * 通过文件获取ScriptProp
     * @param file 目标文件
     */
    public static ScriptProp getScriptByFile(File file){
        ScriptProp scriptProp = new ScriptProp();
        scriptProp.id = file.getPath();
        scriptProp.path = file.getPath();
        scriptProp.name = file.getName();
        scriptProp.type = "javascript";
        scriptProp.size = file.length();
        scriptProp.updateTime = file.lastModified() == 0L ? System.currentTimeMillis() : file.lastModified();
        return scriptProp;
    }

    @Override
    public String toString() {
        return "ScriptProp{" +
                "id='" + id + '\'' +
                ", path='" + path + '\'' +
                ", type='" + type + '\'' +
                ", name='" + name + '\'' +
                ", size=" + size +
                ", updateTime=" + updateTime +
                '}';
    }
}
